//
//  LGPatientAttendHeaderCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/5/24.
//

#import "LGPatientAttendHeaderCell.h"

#define nameWidth     (isPad ? viewPix(280) : viewPix(110))

#define resultWidth   (isPad ? viewPix(140) : viewPix(70))

#define itemWidth   (Screen_W-viewPix(32)-viewPix(16)-viewPix(15)-nameWidth-resultWidth)/2.0

@interface LGPatientAttendHeaderCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *resultLabel;
/**   */
@property (nonatomic , strong)UILabel *rangeLabel;
/**   */
@property (nonatomic , strong)UILabel *unitLabel;
/**   */
@property (nonatomic , strong)CAGradientLayer *shadowLayer;
@end

@implementation LGPatientAttendHeaderCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setTitle:(NSString *)title{
    _title = title;
    self.nameLabel.text = title;
}

//-(void)layoutSubviews{
//    [super layoutSubviews];
//    self.shadowLayer.frame = CGRectMake(viewPix(16), 0, Screen_W-viewPix(32), self.contentView.bounds.size.height);
//}

-(CAGradientLayer *)shadowLayer{
    if(!_shadowLayer){
        _shadowLayer = [[CAGradientLayer alloc]init];
        _shadowLayer.frame = self.bounds;
        _shadowLayer.startPoint = CGPointMake(0.5, 0);
        _shadowLayer.endPoint = CGPointMake(0.5, 1);
        _shadowLayer.colors = @[(__bridge id)[UIColor colorWithString:@"#FFFFFF" alpha:1].CGColor, (__bridge id)[UIColor colorWithString:@"#FFFFFF" alpha:1].CGColor];
        _shadowLayer.locations = @[@(0), @(1.0f)];
    }
    return _shadowLayer;
}

-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.resultLabel];
    [self.contentView addSubview:self.rangeLabel];
    [self.contentView addSubview:self.unitLabel];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(self.contentView).offset(viewPix(16));
        make.top.right.equalTo(self.contentView).offset(-viewPix(16));
        make.height.equalTo(@(viewPix(32)+35));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(viewPix(12));
        make.centerY.equalTo(self.contentView);
        make.width.equalTo(@(nameWidth));
    }];
    
    [self.resultLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.nameLabel);
        make.width.equalTo(@(resultWidth));
    }];
    [self.rangeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.resultLabel.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.nameLabel);
        make.width.equalTo(@(itemWidth));
    }];
    [self.unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.rangeLabel.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.nameLabel);
        make.width.equalTo(@(itemWidth));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:10];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#1F6CC6" textFont:LGFontWeight(13, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _nameLabel;
}


-(UILabel *)resultLabel{
    if(!_resultLabel){
        _resultLabel = [UILabel lableWithText:@"结果" colorString:@"#666666" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _resultLabel;
}

-(UILabel *)rangeLabel{
    if(!_rangeLabel){
        _rangeLabel = [UILabel lableWithText:@"参考值" colorString:@"#666666" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _rangeLabel;
}

-(UILabel *)unitLabel{
    if(!_unitLabel){
        _unitLabel = [UILabel lableWithText:@"单位" colorString:@"#666666" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _unitLabel;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
